package it.univaq.mancoosi.injectors.systemconfiguration.managers.ubuntu;

import java.io.IOException;
import it.univaq.mancoosi.injectors.systemconfiguration.managers.InformationFileManager;

public class UbuntuInformationFileManager extends InformationFileManager {

	public UbuntuInformationFileManager(){
		super();
	}

	public static InformationFileManager getInstance() {
		if (INSTANCE == null)
			INSTANCE = new UbuntuInformationFileManager();
		return INSTANCE;
	}
	
	@Override
	public void createInformationFileFromSystem() {
		try {
			java.io.File infoFile = new java.io.File("/usr/share/info");

			if(infoFile.exists()){
				UbuntuFileSystemManager.getInstance().createFile("/usr/share/info");
			}			

		} catch (Exception err) {
			err.printStackTrace();
		}	

	}

	@Override
	public void synchronize() throws IOException {
		try {
			java.io.File infoFile = new java.io.File("/usr/share/info");

			if(infoFile.exists()){
				if(UbuntuFileSystemManager.getInstance().getInformationFile() == null){
					UbuntuFileSystemManager.getInstance().createFile("/usr/share/info");
				}				
			}else{
				if(UbuntuFileSystemManager.getInstance().getInformationFile() != null){
					UbuntuFileSystemManager.getInstance()
						.deleteFile(UbuntuFileSystemManager.getInstance().getInformationFile().getLocation());
					
				}
			}			

		} catch (Exception err) {
			err.printStackTrace();
		}	
		

	}

}
